//
//  CertificationViewController.m
//  InviteJob
//
//  Created by LangLang on 17/11/1.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "CertificationViewController.h"
#import "TeamViewController.h"
#import "CompanyViewController.h"


@interface CertificationViewController ()
{
    UIButton *_btn_page;
    UIView *xian;
    NSInteger _index_btnCl;
    UIScrollView *_scrollView;
    
    NSString * indexStr;
}
@property (nonatomic,strong) CompanyViewController *company;
@property (nonatomic,strong) TeamViewController *team;
@property (nonatomic, strong) UIButton *navRightButton;


@end

@implementation CertificationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    TitleView(@"企业/团队认证")
    
    [self my_button];
    
    // right item
    self.navRightButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    [self.navRightButton setTitle:@"保存" forState:UIControlStateNormal];
    self.navRightButton.titleEdgeInsets = UIEdgeInsetsMake(0,10, 0, -10);
    self.navRightButton.titleLabel.font = [UIFont systemFontOfSize:16];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:self.navRightButton];
    self.navigationItem.rightBarButtonItem = rightItem;
    [self.navRightButton addTarget:self action:@selector(navSaveAction) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)navSaveAction {
    if (_index_btnCl == 0) {
         [[NSNotificationCenter defaultCenter] postNotificationName:@"buttonCompany" object:@"buttonCompany" userInfo:nil];
    }else{
        [[NSNotificationCenter defaultCenter] postNotificationName:@"buttonTeam" object:@"buttonTeam" userInfo:nil];
    }
    
}


-(void)my_button{
    NSArray *arr=@[@"公司认证",@"团队认证"];
    for (int i=0; i<arr.count; i++) {
        _btn_page=[UIButton buttonWithType:UIButtonTypeSystem];
        _btn_page.backgroundColor=[UIColor whiteColor];
        _btn_page.frame=CGRectMake(WIDTH/2*i, 0, WIDTH/2, 50);
        _btn_page.tag=1000+i;
        [_btn_page setTitle:arr[i] forState:UIControlStateNormal];
        [self.view addSubview:_btn_page];
        [_btn_page addTarget:self action:@selector(btnPage:) forControlEvents:UIControlEventTouchUpInside];
        [_btn_page setTitleColor:strColor(@"333") forState:UIControlStateNormal];
        if (i==_index_btnCl) {
            [_btn_page setTitleColor:NavBackColor forState:UIControlStateNormal];
        }
        
    }
    UIView* xian1=[[UIView alloc] initWithFrame:CGRectMake(0, 50, WIDTH, 11)];
    xian1.backgroundColor=strColor(@"f6f6f6");
    [self.view addSubview:xian1];
    
    xian=[[UIView alloc] initWithFrame:CGRectMake(WIDTH/4.4, _btn_page.center.y+24, WIDTH/6 / 2, 1)];
    xian.backgroundColor=NavBackColor;
    [self.view addSubview:xian];
    
    _company = [CompanyViewController new];
     _company.view.frame = CGRectMake(0, 50+10, WIDTH, HEIGHT-50-10);
    [self addChildViewController:_company];
    [self.view addSubview:_company.view];
}
-(void)btnPage:(UIButton *)btn{
    NSInteger i=btn.tag-1000;
    if (i==_index_btnCl) {
        return;
    }
    UIButton *oldbtn=[self.view viewWithTag:1000+_index_btnCl];
    [oldbtn setTitleColor:strColor(@"333") forState:UIControlStateNormal];
    [_scrollView setContentOffset:CGPointMake(i * WIDTH, 0) animated:YES];
    [btn setTitleColor:NavBackColor forState:UIControlStateNormal];
    
    xian.backgroundColor = NavBackColor;
    xian.center=CGPointMake(btn.center.x, btn.center.y+24);
    _index_btnCl=i;
    if (btn.tag == 1000) {
        [_team.view removeFromSuperview];
        _company = [CompanyViewController new];
         _company.view.frame = CGRectMake(0, 50+10, WIDTH, HEIGHT-64-50-10);
        [self addChildViewController:_company];
        [self.view addSubview:_company.view];
        
    }else if (btn.tag == 1001){
        [_company.view removeFromSuperview];
        _team = [TeamViewController new];
         _team.view.frame = CGRectMake(0, 50+10, WIDTH, HEIGHT-64-50-10);
        [self addChildViewController:_team];
        [self.view addSubview:_team.view];
        
    }
}

@end
